package com.learn.greedy;

import java.util.PriorityQueue;

/**
 * 最小代价
 */
public class MinCost {

    public int lessMoney(int[] arr) {
        PriorityQueue<Integer> queue = new PriorityQueue<>();
        for (int i : arr) {
            queue.add(i);
        }
        int res = 0;
        while (!queue.isEmpty()) {
            int cost = queue.poll() + queue.poll();
            res += cost;
            queue.add(cost);
        }
        return res;
    }
}
